// 引入axios
import axios from 'axios'
export default {
  namespaced: true,
  state: {
    token: '',
    userInfo: {}
  },
  getters: {
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
    },
    updateUserInfo(state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async getUserInfo(context) {
      const { data: res } = await axios.get('/my/userinfo', {
        headers: {
          Authorization: context.state.token
        }
      })
      // console.log(res)
      if (res.code !== 0) return
      context.commit('updateUserInfo', res.data)
    }
  }
}
